OPC Studio User's Guide and Reference
OPC Server Dialog (OPC DA usage)
Concepts > QuickOPC Concepts > QuickOPC Features > QuickOPC User Interface Features > OPC Common Dialogs > OPC-DA Common Dialogs > OPC Server Dialog (OPC DA usage)
In This Topic

General

Icon :

If you do not know upfront which OPC server to connect to, and do not have this information from any other source, your application will need to allow the user select the OPC server(s) to work with. The OPC Server Dialog (OpcServerDialog class) allows the user to select the OPC server interactively from the list of OPC Data Access servers installed on a particular machine.

Here is an example of OPC Server dialog in action:

The ServerFamilies property of the dialog determines whether OPC Data Access servers, OPC Alarms&Events servers, other servers, or a combination of them will be browsed. By default, all server families are browsed. In order to limit the browsing to OPC Data Access servers only, set the ServerFamilies property to the OpcDataAccess enumeration member.

To run the dialog, set the Location property to the name of the computer that is to be browsed, and call the ShowDialog method. If the result is equal to DialogResult.OK, the user has selected the OPC Data Access server, and information about it can be retrieved from the ServerElement property.

.NET

// This example shows how to let the user browse for an OPC "Classic" server.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
// OPC client and subscriber examples in C# on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-CSharp .
// Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
// a commercial license in order to use Online Forums, and we reply to every post.

using System.Windows.Forms;
using OpcLabs.EasyOpc.Forms.Browsing;

namespace FormsDocExamples._OpcServerDialog
{
    static class ShowDialog
    {
        public static void Main1(IWin32Window owner)
        {
            var serverDialog = new OpcServerDialog();
            //serverDialog.Location = "";

            DialogResult dialogResult = serverDialog.ShowDialog(owner);
            if (dialogResult != DialogResult.OK)
                return;

            // Display results
            MessageBox.Show(owner, serverDialog.ServerElement);
        }
    }
}
# This example shows how to let the user browse for an OPC "Classic" server.
#
# Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
# OPC client and subscriber examples in PowerShell on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-PowerShell .
# Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
# a commercial license in order to use Online Forums, and we reply to every post.

# The path below assumes that the current directory is [ProductDir]/Examples-NET/PowerShell/Windows .
Add-Type -Path "../../../Components/Opclabs.QuickOpc/net472/OpcLabs.EasyOpcForms.dll"

$serverDialog = New-Object OpcLabs.EasyOpc.Forms.Browsing.OpcServerDialog
#$serverDialog.Location = ""

$dialogResult = $serverDialog.ShowDialog()
if ($dialogResult -ne [System.Windows.Forms.DialogResult]::OK) {
    return
}

# Display results
Write-Host $serverDialog.ServerElement
' This example shows how to let the user browse for an OPC "Classic" server.
'
' Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
' OPC client and subscriber examples in VB.NET on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-VBNET .
' Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
' a commercial license in order to use Online Forums, and we reply to every post.

Imports OpcLabs.EasyOpc.Forms.Browsing

Namespace FormsDocExamples._OpcServerDialog
    Friend Class ShowDialog
        Shared Sub Main1(owner As IWin32Window)
            Dim serverDialog = New OpcServerDialog()
            'serverDialog.Location = "" 

            Dim dialogResult As DialogResult = serverDialog.ShowDialog(owner)
            If dialogResult <> DialogResult.OK Then
                Return
            End If

            ' Display results
            MessageBox.Show(owner, serverDialog.ServerElement)
        End Sub
    End Class
End Namespace

COM

// This example shows how to let the user browse for an OPC "Classic" server.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
// OPC client and subscriber examples in Object Pascal (Delphi) on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-OP .
// Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
// a commercial license in order to use Online Forums, and we reply to every post.

class procedure ShowDialog.Main;
var
  ServerDialog: OpcLabs_EasyOpcForms_TLB._OpcServerDialog;
begin
  // Instantiate the dialog object
  ServerDialog := CoOpcServerDialog.Create;

  ServerDialog.ShowDialog(nil);

  // Display results
  WriteLn(ServerDialog.ServerElement.ToString);
end;
Rem This example shows how to let the user browse for an OPC "Classic" server.
Rem
REM Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
REM OPC client and subscriber examples in Visual Basic on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-VB .
REM Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
REM a commercial license in order to use Online Forums, and we reply to every post.

Private Sub ShowDialog_Main_Command_Click()
    OutputText = ""

    ' Instantiate the dialog object
    Dim serverDialog As New OpcServerDialog
    Dim DialogResult
    DialogResult = serverDialog.ShowDialog
    
    OutputText = OutputText & DialogResult & vbCrLf
    If DialogResult <> 1 Then   ' OK
        Exit Sub
    End If
    
    ' Display results
    OutputText = OutputText & serverDialog.ServerElement & vbCrLf
End Sub
Rem This example shows how to let the user browse for an OPC "Classic" server.
Rem
Rem Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
Rem OPC client and subscriber examples in VBScript on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-VBScript .
Rem Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
Rem a commercial license in order to use Online Forums, and we reply to every post.

Option Explicit

Const DialogResult_OK = 1

Dim ServerDialog: Set ServerDialog = CreateObject("OpcLabs.EasyOpc.Forms.Browsing.OpcServerDialog")
'ServerDialog.Location = ""
Dim dialogResult: dialogResult = ServerDialog.ShowDialog
WScript.Echo dialogResult

If dialogResult <> DialogResult_OK Then
    WScript.Quit
End If

' Display results
WScript.Echo ServerDialog.ServerElement

Python

# This example shows how to let the user browse for an OPC "Classic" server.
#
# Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
# OPC client and subscriber examples in Python on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-Python .
# Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
# a commercial license in order to use Online Forums, and we reply to every post.
# The QuickOPC package is needed. Install it using "pip install opclabs_quickopc".
import opclabs_quickopc

# Import .NET namespaces.
from System.Windows.Forms import *
from OpcLabs.EasyOpc.Forms.Browsing import *


serverDialog = OpcServerDialog()
#serverDialog.Location = ''

dialogResult = serverDialog.ShowDialog()
print(dialogResult)
if dialogResult != DialogResult.OK:
    exit()

# Display results.
print('ServerElement: ', serverDialog.ServerElement, sep='')

 

Advanced

If you want to change the parameters of the client objects the component uses to perform its OPC operations, you can use the DAClientSelector Property or the AEClientSelector Property.

 

See Also